package com.asion.qkan.ui.model;

import com.asion.qkan.api.ServiceApi;
import com.asion.qkan.entry.AllContentBean;
import com.asion.qkan.entry.HomeBean;
import com.asion.qkan.ui.contract.AllContentContract;
import com.asion.qkan.ui.contract.HomeContract;
import com.asion.qkan.utils.retrofitCache.SetCacheUtils;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by HCJ on 2016/10/16.
 */

public class AllContentModel implements AllContentContract.Model{
    @Override
    public void getAllContentDatas(String id, AllContentContract.OnAllContentListener onAllContentListener) {
        //请求数据
        new Retrofit.Builder()
                .baseUrl("http://api.kkmh.com/")
                .client(SetCacheUtils.setCache())
                .addConverterFactory(GsonConverterFactory.create())//创建Gson解析的Factory
                .build()
                .create(ServiceApi.class)
                .getAllContent(id)
                .enqueue(new Callback<AllContentBean>() {
                    @Override
                    public void onResponse(Call<AllContentBean> call, Response<AllContentBean> response) {
                        AllContentBean body = response.body();
                        onAllContentListener.onAllContentSuccess(body);
                    }

                    @Override
                    public void onFailure(Call<AllContentBean> call, Throwable t) {
                        onAllContentListener.onAllContentError(t);
                    }
                });

    }
}
